package com.yc.favorite.mapper;

import com.yc.favorite.bean.Favorite;
import com.yc.favorite.bean.Tag;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface FavoriteMapper {

    @Insert("insert into favorite values (default, #{flabel}, #{furl}, #{fdesc}, #{ftags})")
    @Options(useGeneratedKeys = true, keyColumn = "fid", keyProperty = "fid")
    int insert(Favorite favorite);

    @Update("update favorite set " +
            " flabel=#{flabel},furl=#{furl},fdesc=#{fdesc},tags=#{ftags}" +
            " where fid=#{fid}")
    int updateCount(Favorite favorite);

    @Select("select * from favorite")
    List<Favorite> selectAll();

    @Select("select * from favorite where tags is null")
    List<Favorite> selectNoTags();

    @Select("select * from favorite a " +
            " join tagfavorite b on a.fid=b.fid " +
            " where b.tid=#{tid}")
    List<Favorite> selectByTid(int tid);

}
